package com.chinasoftinc.facommon;

import ohos.aafwk.ability.Ability;
import ohos.aafwk.ability.AbilityPackage;
import ohos.agp.render.render3d.BuildConfig;
import ohos.app.Context;

import com.chinasoftinc.facommon.control.service.HilinkDeviceServiceAbility;
import com.chinasoftinc.facommon.utils.LogUtil;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * FAApplication, 接入FA项目需继承此Application
 *
 * @since 2022-05-13
 */
public class FAApplication extends AbilityPackage {
    public static final String TAG = "FAApplication";
    private static Context context;
    private static final AtomicInteger loadedPageStack = new AtomicInteger(0);
    private static final ScheduledExecutorService taskScheduler = Executors.newSingleThreadScheduledExecutor();

    @Override
    public void onInitialize() {
        super.onInitialize();
        context = this;
        loadedPageStack.set(0);
        // 通用远程服务操作
        CommonAbility.get().startServer();
        // 消息订阅服务, 如不需要此功能可移除
        EventInternalAbility.get().startServer();
        LogUtil.info(getClass().getSimpleName(), "FACommon.version: " + BuildConfig.VERSION_NAME);
    }

    @Override
    public void onEnd() {
        super.onEnd();
        CommonAbility.get().stopServer();
        EventInternalAbility.get().stopServer();
    }

    public static Context getAppContext() {
        return context;
    }
}
